{%extends file="base_content.html"%}
{%block name="breadcrumb"%}
<li><a href="index.php?c=user">文章管理</a></li>
<li class="active">编辑</li>
{%/block%}

{%block name="content"%}

<h3 class="lighter block green">编辑文章信息</h3>

<form class="form-horizontal" id="validation-form" method="post" role="form" enctype="multipart/form-data">
    {%include file="inc_form_result.html"%}
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="username">文章标题:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <input type="text" name="article_title" id="username" class="col-xs-12 col-sm-6"
                        value="{%$entity.article_title%}" />
            </div>
        </div>
    </div>

    <div class="space-2"></div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="photoCover">文章图片:</label>

        <div class="col-xs-12 col-sm-9">
            <input id="lefile" type="file" name="pic" style="display:none" onchange="$('#photoCover').val($(this).val());  ">  
              <div class="input-append">  
                  <input name="article_pic" id="photoCover" class="input-large" value="{%$entity.article_pic%}" type="text" style="height:30px;">  
                  <a class="btn" onclick="$('input[id=lefile]').click();">Browse</a>  
              </div>  
        </div>
    </div>

    <div class="space-2"></div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="photoCover_thumb">文章缩略图图片:</label>

        <div class="col-xs-12 col-sm-9">
            <input id="lefile_thumb" type="file" name="pic_thumb" style="display:none" onchange="$('#photoCover_thumb').val($(this).val());  ">  
              <div class="input-append">  
                  <input name="article_pic_thumb" id="photoCover_thumb" class="input-large" value="{%$entity.article_pic_thumb%}" type="text" style="height:30px;">  
                  <a class="btn" onclick="$('input[id=lefile_thumb]').click();">Browse</a>  
              </div>  

        </div>
    </div>
    <div class="space-2"></div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="article_url">跳转链接:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <input type="text" name="article_url" id="article_url" class="col-xs-12 col-sm-6" value="{%$entity.article_url%}"/>
            </div>
        </div>
    </div>

    <div class="space-2"></div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="article_sort">排序:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <input type="text" name="article_sort" id="article_sort" class="col-xs-12 col-sm-6" value="{%$entity.article_sort%}"/>
            </div>
        </div>
    </div>

    <div class="space-2"></div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="article_content">内容:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <textarea name="article_content"  id="article_content" class="col-xs-12 col-sm-6">{%$entity.article_content%}</textarea>
            </div>
        </div>
    </div>

   <!-- <div class="hr hr-dotted"></div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="truename">姓名:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <input type="text" name="truename" id="truename" class="col-xs-12 col-sm-6"
                       value="{%$entity.truename|default:''%}" />
            </div>
        </div>
    </div>

    <div class="space-2"></div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="email">邮箱:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <input type="email" id="email" name="email" class="col-xs-12 col-sm-6"
                       value="{%$entity.email|default:''%}" />
            </div>
        </div>
    </div>
-->

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="article_show">是否展示:</label>

        <div class="col-xs-12 col-sm-9">
            <div class="clearfix">
                <label>
                    <input name="article_show" id="article_show" class="ace ace-switch ace-switch-6" type="checkbox"
                           {%if $entity.article_show|default:''==1%}checked{%/if%}  value="1"/>
                    <span class="lbl"></span>
                </label>
            </div>
        </div>
    </div>

    <div class="clearfix form-actions">
        <div class="col-md-offset-3 col-md-9">
            <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                提交
            </button>

            &nbsp; &nbsp; &nbsp;
            <a class="btn" href="index.php?c=user">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                返回
            </a>
        </div>
    </div>
</form>


{%/block%}

{%block name="js"%}
<script>
      $(function(){
        $('input[id=lefile]').on("change",function() { 
              $('#photoCover').val($(this).val());  
            });  
        $('input[id=lefile_thumb]').on("change",function() { 
              $('#photoCover_thumb').val($(this).val());  
            });  
          jQuery.validator.addMethod("username", function (value, element) {
              return this.optional(element) || /^[_a-zA-Z0-9]+$/.test(value);
          }, "账号只能包含数字，字母，下划线");
          $('#validation-form').validate({
              errorElement: 'div',
              errorClass: 'help-block',
              focusInvalid: false,
              rules: {
                  email: {
                      required: true,
                      email:true
                  },
                  password: {
                  {%if $smarty.request.m=='add'%}required: true,{%/if%}
                      minlength: 6,
                      maxlength: 15
                  },

                  username: {
                      required: true,
                      minlength: 3,
                      maxlength: 15,
                      username: 'required'
                  }
                  ,

                  truename: {
                      required: true,
                      minlength: 2,
                      maxlength: 15
                  }
              },

              messages: {
                  email: {
                      required: "请输入邮箱",
                      email: "请输入正确邮箱格式"
                  },
                  password: {
                      required: "请输入密码",
                      minlength: "密码需要6-12个字符",
                      maxlength: "密码需要6-15个字符"
                  },
                  username: {
                      required: "请输入账号",
                      minlength: "账号需要3-15个字符",
                      maxlength: "账号需要3-15个字符"
                  },
                  truename: {
                      required: "请输入姓名",
                      minlength: "姓名需要2-15个字符",
                      maxlength: "姓名需要2-15个字符"
                  }
              },



              highlight: function (e) {
                  $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
              },

              success: function (e) {
                  $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                  $(e).remove();
              },

              errorPlacement: function (error, element) {
                  if(element.is(':checkbox') || element.is(':radio')) {
                      var controls = element.closest('div[class*="col-"]');
                      if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
                      else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                  }
                  else if(element.is('.select2')) {
                      error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                  }
                  else if(element.is('.chosen-select')) {
                      error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                  }
                  else error.insertAfter(element.parent());
              }


          });
      });
</script>
{%/block%}